<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">

</head>
<body>
<div class="x-nav">
<span class="layui-breadcrumb">
        <a href="#">小程序管理</a>
        <a href="#">体育资讯</a>
        <a href="#">编辑详细信息</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form class="layui-form" action="" onsubmit="return false" style="width: 600px;padding-top: 5px">
    <input type="text" value="{$data.id}" hidden id="id">
    <input value="{$data.image}" type="hidden" name="image" id="imgs">
    <div class="layui-form-item" >
        <label class="layui-form-label" style="width: 100px">标题</label>
        <div class="layui-input-block">
            <input type="text" value="{$data.title}" id="title"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">原图片</label>
        <div class="layui-input-block">
            {if strlen($data.image) > 0}
                <img src="/uploads/news/title_img/{$data.image}" style="width: 150px;height: auto">
            {else/}
                无
            {/if}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">图片</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>
    <div class="layui-form-item" id="news_image" style="display: none">
        <label class="layui-form-label" style="width: 100px">新图片</label>
        <div class="layui-input-block">
            <img src="" style="width: 150px;height: auto" id="upload_img">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">内容</label>
        <div class="layui-input-block" >
            <textarea id="demo" style="display: none;">{$data.content}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">发布时间</label>
        <div class="layui-input-block" >
            <input type="text" value="{$data.create_time}" name="title"  readonly="readonly" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="add">立即更新</button>
            <button id="back" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use(['layedit','form','upload'], function(){
        layedit = layui.layedit;
        var upload = layui.upload;
        upload.render({
            elem: '#upload' //绑定元素
            ,url: "{:url('/common/img')}" //上传接口
            ,data: {path:"/public/uploads/news/title_img/"}
            ,done: function(res){
                if(res.error){
                    layer.msg(res.error,{icon:5,time:2000});
                    return
                }else{
                    $("#imgs").val(res.img);
                    $("#news_image").css('display','block');
                    $("#upload_img").attr('src','/uploads/news/title_img/'+res.img)
                }
            }
        });
        layedit.set({
            uploadImage: {
                url: "{:url('/common/imgLayui')}" //接口url
                ,type: 'post' //默认post
            }
        });
        index = layedit.build('demo',
            {    tool: ['strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线
                ,'del' //删除线
                ,'image' //插入图片
            ]}
        ); //建立编辑器
        layedit.getContent(index)
    });
</script>
<script>
    $("#add").click(function () {
        var content = layedit.getContent(index);
        var title   = $("#title").val();
        var id      = $("#id").val();
        var image    = $("#imgs").val();
        if(!content && !title && !id){
            layer.msg('所有信息，不能为空',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/news/updateHeart')}",
            data:{title:title,id:id,content:content,image:image},
            type:'post',
            dataType:"json",
            success:function (res) {
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        $("#adminList").bootstrapTable(('refresh'));
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    return;
                }
            }
        })
    })
    $("#back").click(function () {
        window.history.go(-1)
    })
</script>